﻿using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace Framework.Mvc
{
    /// <summary>
    /// 分页列表的视图模型
    /// </summary>
    public class PagedListViewModel<TList> : ListViewModel<TList> where TList : class
    {
        /// <summary>
        /// 当前页
        /// </summary>
        [DisplayName("当前页")]
        public int CurrentPage { get; set; }

        /// <summary>
        /// 页面大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总条数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int Pages
        {
            get
            {
                return Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Total) / Convert.ToDouble(PageSize)));
            }
        }

        /// <summary>
        /// 下一页
        /// </summary>
        [DisplayName("下一页")]
        public int NextPage
        {
            get
            {
                int i = this.CurrentPage + 1;
                if (i > this.Pages)
                {
                    return this.Pages;
                }
                else
                {
                    return i;
                }
            }
        }

        /// <summary>
        /// 上一页
        /// </summary>
        [DisplayName("上一页")]
        public int PrePage
        {
            get
            {
                int i = this.CurrentPage - 1;
                if (i <= 0)
                {
                    return 1;
                }
                else
                {
                    return i;
                }
            }
        }
    }
}